package com.yc.homepage.client;

import com.yc.homepage.CourseInfo;
import com.yc.homepage.CourseInfosRequest;
import com.yc.homepage.CourseInfosRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * <h1>通过 Feign 访问课程微服务</h1>
 * FeignClient 表示feign, value 表示配置中spring application name
 * fallback 熔断降级策略
 */
@FeignClient(value = "eureka-client-homepage-course",
        fallback = CourseClientHystrix.class)
public interface CourseClient {

    /**
     * 这些动作都是由feign帮忙完成
     *  value  url 定义
     *  method 请求方式
     * @param id
     * @return
     */
    @RequestMapping(value = "/homepage-course/get/course",
            method = RequestMethod.GET)
    CourseInfo getCourseInfo(Long id);

    /**
     * post 方法需要加入@RequestBody
     * @param request
     * @return
     */
    @RequestMapping(value = "/homepage-course/get/courses", method = RequestMethod.POST)
    List<CourseInfo> getCourseInfos(@RequestBody CourseInfosRequest request);
}
